<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		*{
			padding:0;
			margin:0;
		}
		#wrap{
			width: 200px;
			height: 350px;
			border:5px solid black;
			margin:100px auto 0;
			position: relative;
			overflow: hidden; 
		}
		img{
			width: 200px;
			height: 350px;
			float: left;
		}
		#content{
			width: 800px;
			height: 350px;
			position: absolute;
			top:0;
			left: 0;
		}
	</style>
</head>
<body>
	<div id="wrap">
		<div id="content">
			<img src="a3.jpg" alt="">
			<img src="a4.jpg" alt="">
			<img src="a5.jpg" alt="">
			<img src="a3.jpg" alt="">
		</div>
	</div>
</body>
</html>
<script>
	//获取元素
	var contentDiv = document.getElementById("content");
    
    //记录初始位置
	var left = 0;

	//var timerId = setInterval(autoscroll,20);
     var timerId = requestAnimationFrame(autoscroll,20);

	function autoscroll(){
		left -= 2;
		contentDiv.style.left = left + "px";
       
       //如果跑到最后一张，切到第一张
		if(left == -600){
			left = 0;
			contentDiv.style.left = left + "px";
		}
         requestAnimationFrame(autoscroll,20);
	}
</script>